package com.xu.cloud.common.sequence.wrapper;

import com.xu.cloud.common.constant.CryptConstant;
import com.xu.cloud.common.sequence.ISequence;
import com.xu.cloud.common.util.MessageDigestUtil;

/**
 * 摘要加密串序列生成器
 *
 * @author xuguan
 * @since 2025/2/12
 */
public class MessageDigestSequenceWrapper implements ISequence {
    private final ISequence sequence;
    private String algorithm = CryptConstant.MD5_DIGEST_ALGORITHM;

    public MessageDigestSequenceWrapper(ISequence sequence) {
        this.sequence = sequence;
    }

    public String getAlgorithm() {
        return algorithm;
    }

    public void setAlgorithm(String algorithm) {
        this.algorithm = algorithm;
    }

    @Override
    public String nextId() {
        return MessageDigestUtil.encryptToHex(sequence.nextId(), algorithm);
    }
}
